package top.houry.springboot.websocket.handler;

import jakarta.websocket.*;
import jakarta.websocket.server.PathParam;
import jakarta.websocket.server.ServerEndpoint;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

@Component
@Slf4j
@ServerEndpoint(value = "/ws/{params}")
public class WebSocketHandler {

    @OnOpen
    public void onOpen(Session session, @PathParam("params") String params) {
        log.info("websocket onOpen");
    }

    @OnClose
    public void onClose(Session session) {
        log.info("websocket onClose");
    }
    @OnError
    public void onError(Throwable error) {
        log.error("websocket onError", error);
    }

    @OnMessage
    public void onMessage(String message) {
        log.info("websocket onMessage:{}", message);
    }

}
